home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / MungeImage Source 1.2.0 / MungeInstaller.p < prev    next >
Encoding:
Text File  |  1994-08-15  |  3.8 KB  |  151 lines  |  [TEXT/PJMM]

  1. program MungeInstaller;
  2.  
  3.     uses
  4.         EPPC, AppleEvents, RequiredEventSupport, MyDriver, MungeLibs, MungeCommon;
  5.  
  6.     const
  7.         Driver_Name = '.MungeImage';
  8.  
  9.     var
  10.         drvr_ref: integer;
  11.         quitNow: boolean;
  12.         have_opened: boolean;
  13.  
  14.     function MyProgress (pb: mungeParamBlockPtr): OSErr;
  15.     begin
  16.         pb^.refcon := band(pb^.refcon + 1, $03);
  17.         SetCursor(GetCursor(128 + pb^.refcon)^^);
  18.         MyProgress := noErr;
  19.     end; (* MyProgress *)
  20.  
  21.     function DoODoc (fss: FSSpec; option: boolean): OSErr;
  22.         var
  23.             err: OSErr;
  24.             pb: mungeParamBlockRec;
  25.     begin
  26.         have_opened := true;
  27.         with pb do begin
  28.             ioCRefNum := drvr_ref;
  29.             csCode := csMountImageWithProgress;
  30.             file_to_mount := @fss;
  31.             mount_flags := 0;
  32.             if option then begin
  33.                 bset(mount_flags, mf_read_write);
  34.             end; (* if *)
  35.             progress := @MyProgress;
  36.             refcon := 0;
  37.         end; (* with *)
  38.         err := PBControlSync(@pb);
  39.         if err = controlErr then begin
  40.             pb.csCode := csMountImage;
  41.             err := PBControlSync(@pb);
  42.         end; (* if *)
  43.         if err <> noErr then begin
  44.             SysBeep(10);
  45.         end; (* if *)
  46.         quitNow := true;
  47.         DoODoc := err;
  48.     end; (* DoODoc *)
  49.  
  50.     function HandleDocs (event, reply: AppleEvent; dodocp: ptr): OSErr;
  51.         var
  52.             myFSS: FSSpec;
  53.             docList: AEDescList;
  54.             index, itemsInList: LONGINT;
  55.             actualSize: Size;
  56.             keywd: AEKeyword;
  57.             typeCode: descType;
  58.             oe, ooe, err: OSErr;
  59.             er: EventRecord;
  60.             realType: DescType;
  61.             realSize: longInt;
  62.             psn: ProcessSerialNumber;
  63.             pi: ProcessInfoRec;
  64.             odoc_with_option: boolean;
  65.     begin
  66.         err := AEGetParamBoolean(event, 'auto', odoc_with_option);
  67.         if err <> noErr then begin
  68.             odoc_with_option := false;
  69.             err := AEGetAttributePtr(event, keyAddressAttr, keyProcessSerialNumber, realType, @psn, SizeOf(psn), realSize);
  70.             if err = noErr then begin
  71.                 pi.processInfoLength := sizeof(ProcessInfoRec);
  72.                 pi.processName := nil;
  73.                 pi.processAppSpec := nil;
  74.                 err := GetProcessInformation(psn, pi);
  75.             end;
  76.             if (err = noErr) & (pi.processSignature = 'MACS') then begin
  77.                 odoc_with_option := OSEventAvail(everyEvent, er);
  78.                 odoc_with_option := BAND(er.modifiers, optionKey) <> 0;
  79.             end;
  80.         end;
  81.         oe := AEGetParamDesc(event, keyDirectObject, typeAEList, docList);
  82.         if oe = noErr then begin
  83.             ooe := GotRequiredParams(event);
  84.     { now get each alias from the list (as an FSSSpec) and open the associated file. }
  85.             oe := AECountItems(docList, itemsInList);
  86.             for index := 1 to itemsInList do begin
  87.                 ooe := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);
  88. { coercion does alias->fsspec }
  89.                 if ooe = noErr then begin
  90.                     ooe := DoODoc(myFSS, odoc_with_option);
  91.                 end; (* if *)
  92.             end;
  93.             ooe := AEDisposeDesc(docList);
  94.         end;
  95.         HandleDocs := oe;
  96.     end; { HandleDocs }
  97.  
  98.     function DoOApp: OSErr;
  99.     begin
  100.         quitNow := true;
  101.         DoOApp := noErr;
  102.     end;
  103.  
  104.     function DoQuit: OSErr;
  105.     begin
  106.         quitNow := true;
  107.         DoQuit := noErr;
  108.     end; (* DoQuit *)
  109.  
  110.     var
  111.         junkbool: boolean;
  112.         event: EventRecord;
  113.         err: OSErr;
  114.         junk: OSErr;
  115.         junk_vref: integer;
  116.         response: longint;
  117. begin
  118.     if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < $700) then begin
  119.         ExitToShell;
  120.     end; (* if *)
  121.     err := InitAppleEvents(@DoOApp, nil, nil, @DoQuit);
  122.     if err = noErr then begin
  123.         err := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @HandleDocs, 0, false);
  124.     end; (* if *)
  125.     if err = noErr then begin
  126.         drvr_ref := GetDriverRefNum(Driver_Name);
  127.         if drvr_ref <> 0 then begin
  128.             err := noErr;
  129.         end
  130.         else begin
  131.             err := InstallRAMDriver(Driver_Name, drvr_ref, true);
  132.         end;
  133.         if err = noErr then begin
  134.             quitNow := false;
  135.             while not quitNow do begin
  136.                 junkbool := WaitNextEvent(everyEvent, event, maxlongint, nil);
  137.                 case event.what of
  138.                     keyDown: 
  139.                         quitNow := true;
  140.                     kHighLevelEvent: 
  141.                         junk := AEProcessAppleEvent(event);
  142.                     otherwise
  143.                         ;
  144.                 end; (* case *)
  145.             end; (* while *)
  146.         end; (* if *)
  147.     end; (* if *)
  148.     if err <> noErr then begin
  149.         SysBeep(10);
  150.     end;
  151. end. (* MungeInstaller *)